[...slug].vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885
  1. <template>
  2. <div>
  3. <SldHomeTopSearch />
  4. <NavCatHeader />
  5. <div class="bottom_line"></div>
  6. <div class="goods_list_container self_background">
  7. <!-- 分类路径 -->
  8. <div class="level_nav_main">
  9. <div class="level_item" v-if="catePathName.path.length">
  10. <!-- 一级分类,显示该部分 -->
  11. <template v-if="1 === showIndex">
  12. <div class="level_nav_item">
  13. <a class="level_link">{{ catePathName.path[0] }}</a>
  14. </div>
  15. <!-- <i class="level-right"></i> -->
  16. <div class="level_nav_item">
  17. <div class="menu_drop">
  18. <div :class="{ trigger: true, hasChild: cate1.cate.length }">
  19. <span class="trigger_name">{{L['全部分类']}}</span>
  20. <i class="menu_drop_arrow"></i>
  21. </div>
  22. <div class="menu_drop_main" v-if="cate1.cate.length">
  23. <ul class="menu_drop_list">
  24. <li
  25. v-for="(
  26. { categoryName, categoryId, grade, pid }, index
  27. ) in cate1.cate"
  28. :key="index"
  29. >
  30. <router-link
  31. :to="'/goods/list/'+ calcProductName(categoryName) +'_v-'+ categoryId + '_gid-' + grade + '_pid-' + pid"
  32. >
  33. {{ categoryName }}</router-link
  34. >
  35. </li>
  36. </ul>
  37. </div>
  38. </div>
  39. </div>
  40. </template>
  41. <!-- 进入二级分类路径下的页面时,显示该部分 -->
  42. <template v-else-if="2 === showIndex">
  43. <div class="level_nav_item">
  44. <div class="menu_drop">
  45. <div :class="{ trigger: true, hasChild: cate1.cate.length }">
  46. <span class="trigger_name">{{ catePathName.path[0] }}</span>
  47. <i class="menu_drop_arrow"></i>
  48. </div>
  49. <div class="menu_drop_main" v-if="cate1.cate.length">
  50. <ul class="menu_drop_list">
  51. <li
  52. v-for="(
  53. { categoryName, categoryId, grade, pid }, index
  54. ) in cate1.cate"
  55. :key="index"
  56. >
  57. <router-link :to="'/goods/list/'+ calcProductName(categoryName) +'_v-'+ categoryId + '_gid-' + grade + '_pid-' + pid">
  58. {{ categoryName }}</router-link>
  59. </li>
  60. </ul>
  61. </div>
  62. </div>
  63. </div>
  64. <i class="level-right"></i>
  65. <div class="level_nav_item">
  66. <div class="menu_drop">
  67. <div :class="{ trigger: true, hasChild: cate2.cate.length }">
  68. <span class="trigger_name">{{ catePathName.path[1] }}</span>
  69. <i class="menu_drop_arrow"></i>
  70. </div>
  71. <div class="menu_drop_main" v-if="cate2.cate.length">
  72. <ul class="menu_drop_list">
  73. <li v-for="(item2, index) in cate2.cate" :key="index">
  74. <Nuxt-link :to="'/goods/list/'+ calcProductName(item2.categoryName) +'_v-'+ item2.categoryId + '_gid-' + item2.grade + '_pid-' + item2.pid" >
  75. {{ item2.categoryName }}
  76. </Nuxt-link>
  77. </li>
  78. </ul>
  79. </div>
  80. </div>
  81. </div>
  82. </template>
  83. <!-- 进入三级分类路径下的页面时,显示该部分 -->
  84. <template v-else>
  85. <div style="float: left">
  86. <div class="level_nav_item">
  87. <div class="menu_drop">
  88. <div :class="{ trigger: true, hasChild: cate1.cate.length }">
  89. <span class="trigger_name">{{ catePathName.path[0] }}</span>
  90. <i class="menu_drop_arrow"></i>
  91. </div>
  92. <div class="menu_drop_main" v-if="cate1.cate.length">
  93. <ul class="menu_drop_list">
  94. <li
  95. v-for="(
  96. { categoryName, categoryId, grade, pid }, index
  97. ) in cate1.cate"
  98. :key="index"
  99. >
  100. <Nuxt-link :to="'/goods/list/'+ calcProductName(categoryName) +'_v-'+ categoryId + '_gid-' + grade + '_pid-' + pid" >
  101. {{ categoryName }}
  102. </Nuxt-link>
  103. </li>
  104. </ul>
  105. </div>
  106. </div>
  107. </div>
  108. <i class="level-right"></i>
  109. <div class="level_nav_item">
  110. <div class="menu_drop">
  111. <div :class="{ trigger: true, hasChild: cate2.cate.length }">
  112. <span class="trigger_name">{{ catePathName.path[1] }}</span>
  113. <i class="menu_drop_arrow"></i>
  114. </div>
  115. <div class="menu_drop_main" v-if="cate2.cate.length">
  116. <ul class="menu_drop_list">
  117. <li
  118. v-for="(
  119. { categoryName, categoryId, grade, pid }, index
  120. ) in cate2.cate"
  121. :key="index"
  122. >
  123. <Nuxt-link :to="'/goods/list/'+ calcProductName(categoryName) +'_v-'+ categoryId + '_gid-' + grade + '_pid-' + pid" >
  124. {{ categoryName }}
  125. </Nuxt-link>
  126. </li>
  127. </ul>
  128. </div>
  129. </div>
  130. </div>
  131. <i class="level-right"></i>
  132. <div class="level_nav_item">
  133. <div class="menu_drop">
  134. <div :class="{ trigger: true, hasChild: cate3.cate.length }">
  135. <span class="trigger_name">{{ catePathName.path[2] }}</span>
  136. <i class="menu_drop_arrow"></i>
  137. </div>
  138. <div class="menu_drop_main" v-if="cate3.cate.length">
  139. <ul class="menu_drop_list">
  140. <li v-for="(item3, index) in cate3.cate" :key="index">
  141. <Nuxt-link :to="'/goods/list/'+ calcProductName(item3.categoryName) +'_v-'+ item3.categoryId + '_gid-' + item3.grade + '_pid-' + item3.pid" >
  142. {{ item3.categoryName }}
  143. </Nuxt-link>
  144. </li>
  145. </ul>
  146. </div>
  147. </div>
  148. </div>
  149. </div>
  150. </template>
  151. <div class="level_nav_item" style="margin-left: 10px">
  152. <div class="menu_drop" v-for="(item, index) in attriListTemp" :key="index">
  153. <div class="trigger label">
  154. <span class="trigger_name"
  155. >{{ item.name }}:&nbsp;<span color="#e2231a">{{ item.value }}</span>
  156. </span>
  157. <span @click="attriKick(index, item)">
  158. <i class="el-icon-close"></i>
  159. </span>
  160. </div>
  161. </div>
  162. </div>
  163. </div>
  164. <div class="level_item" v-show="keyword">
  165. <div class="level_nav_item" style="font-size: 13px">
  166. <a class="level_link"
  167. ><i style="color: #e22319">"{{ keyword }}" &nbsp;</i>{{L['搜索结果']}}</a
  168. >
  169. </div>
  170. </div>
  171. </div>
  172. <div class="goods_list_banner">
  173. <!-- 二级分类或者三级分类的组件 -->
  174. <GoodsListCate2
  175. :cateItem="cate1.child"
  176. :cate2Name="catePathName.path[0]"
  177. v-if="showIndex === 1"
  178. >
  179. </GoodsListCate2>
  180. <GoodsListCate2
  181. :cateItem="cate2.child"
  182. :cate2Name="catePathName.path[1]"
  183. v-if="showIndex === 2"
  184. >
  185. </GoodsListCate2>
  186. <GoodsListCate3
  187. :categoryid="categoryId3"
  188. :pid="Pids"
  189. v-if="showIndex === 3"
  190. @attriOption="attriOption"
  191. @brandOption="brandOption"
  192. ref="goodsCate3"
  193. ></GoodsListCate3>
  194. </div>
  195. <div class="goods_list clearfix">
  196. <!-- 筛选区域 -->
  197. <div class="sld_screen">
  198. <a @click="filterSort(0)" :class="0 == indexNum ? 'btn_sort' : ''">{{
  199. L["综合"]
  200. }}</a>
  201. <div class="goods_type">
  202. {{ L["商品类型"] }}:
  203. <p style="cursor: pointer">
  204. <input
  205. type="checkbox"
  206. :value="isOwnShop"
  207. id="isOwn"
  208. @input="filterStoreSelf(isOwnShop)"
  209. />
  210. <label for="isOwn" style="cursor: pointer">{{ L["仅平台自营"] }}</label>
  211. </p>
  212. </div>
  213. <span class="sld_goods_num">{{ goodsData.page.total }}{{ L["件相关商品"] }}</span>
  214. </div>
  215. <!-- 商品列表 -->
  216. <ul :class="{ sld_goods_list: true, skeleton_sld_goods_list: firstLoading }">
  217. <li
  218. v-for="(
  219. {
  220. goodsDefaultName,
  221. goodsName,
  222. goodsImage,
  223. goodsPrice,
  224. goodsMoney,
  225. saleNum,
  226. activityList,
  227. isFollowGoods,
  228. defaultProductId,
  229. storeName,
  230. isOwnShop,
  231. goodsId,
  232. storeId,
  233. },
  234. index
  235. ) in firstLoading ? skeletonData.data : goodsData.data"
  236. :key="index"
  237. >
  238. <div>
  239. <div class="sld_img sld_img_center">
  240. <router-link
  241. target="_blank"
  242. :to="'/goods/detail/'+ calcProductName(goodsDefaultName) +'_'+ defaultProductId"
  243. >
  244. <img :src="goodsImage" alt="" />
  245. </router-link>
  246. </div>
  247. <div class="sld_h32_hide">
  248. <router-link
  249. class="sld_goods_name"
  250. target="_blank"
  251. :to="'/goods/detail/'+ calcProductName(goodsDefaultName) +'_'+ defaultProductId"
  252. >
  253. <span v-html="goodsName"></span>
  254. </router-link>
  255. </div>
  256. <p class="clearfix">
  257. <span class="sld_goods_price fl"><em>{{ goodsMoney == null ? 'Contact us to give you an individual quote' : goodsMoney}}</em></span>
  258. </p>
  259. <div class="sld_vendor_name">
  260. <router-link
  261. target="_blank"
  262. :to="'/store/'+ calcProductName(storeName) +'_'+ storeId"
  263. class="sld_vendor_name"
  264. @click.stop
  265. >
  266. <span>{{ storeName }}</span>
  267. <span class="el-icon-arrow-right"></span>
  268. </router-link>
  269. </div>
  270. <div class="tag flex_row_start_center">
  271. <div class="is_own" v-if="isOwnShop == 1">{{L['自营']}}</div>
  272. <div v-if="isOwnShop == 2" style="height:18px;"></div>
  273. <div
  274. class="tag_b"
  275. :class="{ tag_b_pre_sale: promotionType == 103 }"
  276. v-for="({ promotionName, promotionType }, index) in activityList"
  277. :key="index"
  278. >
  279. {{ promotionName }}
  280. </div>
  281. </div>
  282. <div class="op_but flex_row_start_center">
  283. <div
  284. class="but_i first flex_row_center_center"
  285. @click.stop="collectGoods(defaultProductId, isFollowGoods)"
  286. >
  287. <div v-if="!isFollowGoods">
  288. <i class="iconfont">&#xe612;</i>{{ L["收藏"] }}
  289. </div>
  290. <div v-else>
  291. <i><img src="/goods/collection.png" class="collection" /></i
  292. >{{ L["已收藏"] }}
  293. </div>
  294. </div>
  295. <div
  296. class="but_i second flex_row_center_center"
  297. @click.stop="addEnquiry(defaultProductId, goodsId)"
  298. >
  299. <div>
  300. <i
  301. ><img
  302. src="/email.svg"
  303. alt=""
  304. width="22"
  305. height="21" /></i
  306. >{{ L["发送询盘"] }}
  307. </div>
  308. </div>
  309. </div>
  310. </div>
  311. </li>
  312. </ul>
  313. <SldCommonEmpty v-show="isEmpty" />
  314. </div>
  315. <!-- 分页 -->
  316. <div class="flex_row_center_center sld_pagination">
  317. <el-pagination
  318. @current-change="handleCurrentChange"
  319. v-model:currentPage.sync="pagitionCurrent"
  320. :page-size="goodsData.page.pageSize"
  321. layout="prev, pager, next"
  322. :total="goodsData.page.total"
  323. :hide-on-single-page="true"
  324. >
  325. </el-pagination>
  326. </div>
  327. <EnquiryModal
  328. v-if="enquiryVis"
  329. :itemType="'GOODS'"
  330. :itemId="productId"
  331. @closeLoingModal="closeEnquiryModal"
  332. />
  333. </div>
  334. </div>
  335. </template>
  336. <script setup>
  337. import { getCurrentInstance, onMounted, reactive, ref, watchEffect, watch } from "vue";
  338. import { ElMessage,ElPagination } from "element-plus";
  339. import { getCurLanguage } from '@/composables/common.js';
  340. import { useFiltersStore } from "@/store/filter.js";
  341. const filtersStore = useFiltersStore();
  342. const proxy = getCurrentInstance();
  343. const L = getCurLanguage();
  344. const enquiryVis = ref(false);
  345. const productId = ref();
  346. //变量------------------------------
  347. const firstLoading = ref(true); //是否第一次加载
  348. const skeletonData = reactive({ data: [] });
  349. const initSkeletonData = () => {
  350. for (let i = 0; i < 10; i++) {
  351. skeletonData.data.push({
  352. goodsDefaultName:"",
  353. goodsName: "",
  354. goodsImage: "",
  355. goodsPrice: "",
  356. goodsMoney:"",
  357. saleNum: "",
  358. activityList: "",
  359. isFollowGoods: "",
  360. defaultProductId: "",
  361. });
  362. }
  363. };
  364. initSkeletonData();
  365. const route = useRoute();
  366. const router = useRouter();
  367. const catePath = ref([]); //导航路径
  368. const showIndex = ref(0); //显示flag
  369. const catePathName = reactive({ path: [] }); //需要在页面显示的整个分类路径
  370. const params = reactive({current: 1});//初始化的请求参数
  371. const goodsData = reactive({ data: [], page: {} });
  372. const indexNum = ref(0);
  373. const lowprice = ref(null);
  374. const highprice = ref(null);
  375. const isEmpty = ref(false);
  376. const cate1 = reactive({ cate: {}, child: {} });
  377. const cate2 = reactive({ cate: {}, child: {} });
  378. const cate3 = reactive({ cate: {} });
  379. const categoryId3 = ref( calcUrlShopId(route.path)? calcUrlShopId(route.path) : '');
  380. const attriList = ref([]);
  381. const attriListTemp = ref([]);
  382. const scrollTop = ref(null);
  383. const priceDidSel = ref(false);
  384. const storeData = reactive({ cat: [] }); //店铺数据,cat:店铺分类,goods:店铺商品列表
  385. const routeParams = reactive({ data: {} })
  386. const pagitionCurrent = ref(1)
  387. const categoryName = ref(calcMallUrlCatName(route.path))
  388. const categoryIds = ref(calcUrlShopId(route.path))
  389. const Gids = ref(calcMallUrlGid(route.path))
  390. const Pids = ref(calcMallUrlPid(route.path))
  391. const cur = ref(calcMallUrlCur(route.path))
  392. const keyword = ref(calcMallUrlKeyword(route.path))
  393. const brand = ref(calcMallUrlBrand(route.path))
  394. //方法------------------------------
  395. const clacRouteParams = () => {
  396. let arr = route.params.slug
  397. let newArr = {}
  398. for(let i in arr){
  399. newArr[arr[i].toString().split('-')[0]] = arr[i].toString().split('-')[1]
  400. }
  401. routeParams.data = newArr
  402. console.log('routeParams',route.path)
  403. if (categoryIds.value) {
  404. params.categoryIds = categoryIds.value
  405. }
  406. if (cur.value) {
  407. params.current = cur.value;
  408. }
  409. if (keyword.value) {
  410. params.keyword = keyword.value;
  411. }
  412. if (routeParams.data.storeId) {
  413. params.storeId = routeParams.data.storeId;
  414. }
  415. if (brand.value) {
  416. params.brandIds = brand.value;
  417. }
  418. getInitData(params);
  419. }
  420. const addEnquiry = (pid,gid) => {
  421. productId.value = pid
  422. enquiryVis.value = true;
  423. };
  424. //关闭登录弹框
  425. const closeEnquiryModal = () => {
  426. enquiryVis.value = false;
  427. };
  428. //初始化数据,进行请求-start
  429. const getInitData = async (params) => {
  430. if (process.client) {
  431. window.scrollTo(0, scrollTop.value);
  432. }
  433. let searchParams = { ...params };
  434. let keys = ''
  435. if(searchParams.categoryIds){
  436. keys += searchParams.categoryIds
  437. }
  438. if(searchParams.keyword){
  439. keys += searchParams.keyword
  440. }
  441. if(searchParams.current){
  442. keys += searchParams.current
  443. }
  444. if(searchParams.isSelf){
  445. keys += searchParams.isSelf
  446. }
  447. if(searchParams.brandIds){
  448. keys += searchParams.brandIds
  449. }
  450. const { data: value, pending: pending } = await useFetchRaw(
  451. apiUrl + "v3/goods/front/goods/goodsList",
  452. {
  453. params: searchParams,
  454. key:keys.toString(),
  455. headers:{Authorization:'Bearer ' + filtersStore.getToken}
  456. }
  457. );
  458. const res = value._rawValue;
  459. if (!pending._rawValue) {
  460. firstLoading.value = false;
  461. }
  462. if (res.state == 200) {
  463. goodsData.data = res.data.list;
  464. isEmpty.value = res.data.list.length ? false : true;
  465. goodsData.page = res.data.pagination;
  466. showIndex.value = Number(Gids.value);
  467. if (categoryIds.value && Gids.value && Pids.value) {
  468. cateForm(categoryIds.value, Gids.value);
  469. }
  470. }
  471. };
  472. //初始化数据,进行请求-end
  473. const SEOinfo = reactive({
  474. seoTitle: "Goods List",
  475. seoDesc: "",
  476. seoKeywords: "",
  477. });
  478. //根据切换数据,改变SEO
  479. const setSEO = () => {
  480. for (let i in storeData.cat) {
  481. if (storeData.cat[i].categoryId == route.query.categoryId) {
  482. SEOinfo.seoTitle = storeData.cat[i].seoInfo.seoTitle;
  483. SEOinfo.seoDesc = storeData.cat[i].seoInfo.seoDesc;
  484. SEOinfo.seoKeywords = storeData.cat[i].seoInfo.seoKeywords;
  485. break;
  486. }else{
  487. for(let j in storeData.cat[i].children){
  488. if(storeData.cat[i].children[j].categoryId == route.query.categoryId){
  489. SEOinfo.seoTitle = storeData.cat[i].children[j].seoInfo.seoTitle;
  490. SEOinfo.seoDesc = storeData.cat[i].children[j].seoInfo.seoDesc;
  491. SEOinfo.seoKeywords = storeData.cat[i].children[j].seoInfo.seoKeywords;
  492. }
  493. }
  494. }
  495. }
  496. useHead({
  497. title: SEOinfo.seoTitle,
  498. meta: [
  499. {
  500. name: "description",
  501. content: SEOinfo.seoDesc,
  502. },
  503. {
  504. name: "keywords",
  505. content: SEOinfo.seoKeywords,
  506. },
  507. ],
  508. });
  509. };
  510. const cateForm = (c, g) => {
  511. if (g == 0) {
  512. return false;
  513. }
  514. if (g == 3) {
  515. let pid = Pids.value
  516. cateForm(pid, 2);
  517. return false;
  518. }
  519. let param = {
  520. categoryId: c,
  521. grade: g,
  522. };
  523. console.log(param)
  524. let cateId = categoryIds.value;
  525. get("v3/goods/front/goods/category/listByPId", param).then((res) => {
  526. if (res.state == 200) {
  527. storeData.cat = res.data;
  528. switch (Number(g)) {
  529. case 1: {
  530. let cdx1 = res.data.findIndex(i => i.categoryId == c)
  531. cate1.cate = res.data.filter(i => i.categoryId != c)
  532. cate1.child = res.data[cdx1].children
  533. catePathName.path[0] = res.data[cdx1].categoryName
  534. if (Gids.value == 2 || Gids.value == 3) {
  535. cate2.cate = cate1.child.filter(i => i.categoryId != cateId)
  536. }
  537. break;
  538. }
  539. case 2: {
  540. cate2.child = res.data[0].children
  541. catePathName.path[1] = res.data[0].categoryName
  542. if (Gids.value == 3) {
  543. let cdx3 = cate2.child.findIndex(i => i.categoryId == cateId)
  544. cate3.cate = cate2.child.filter(i => i.categoryId != cateId)
  545. catePathName.path[2] = cate2.child[cdx3].categoryName
  546. }
  547. let cate2Pid = res.data[0].pid
  548. cateForm(cate2Pid, 1)
  549. break;
  550. }
  551. }
  552. setSEO();
  553. }
  554. });
  555. };
  556. const categorySearch = (data, val) => {
  557. //遍历分类列表,找到该categoryId所在的id路径
  558. for (var i = 0; i < data.length; i++) {
  559. if (data[i] && data[i].categoryId == val) {
  560. return [
  561. {
  562. categoryId: val,
  563. categoryName: data[i].categoryName,
  564. children: data[i].children,
  565. },
  566. ];
  567. }
  568. if (data[i] && data[i].children) {
  569. var d = categorySearch(data[i].children, val);
  570. if (d)
  571. return d.concat({
  572. categoryId: data[i].categoryId,
  573. categoryName: data[i].categoryName,
  574. children: data[i].children,
  575. });
  576. }
  577. }
  578. };
  579. //获取分类Id数组对应的分类名--end
  580. //页数改变的方法-start
  581. const handleCurrentChange = (e) => {
  582. let path = ''
  583. if(!calcMallUrlCur(route.path)){
  584. path = route.path+'_cur-'+e
  585. }else{
  586. let arr = route.path.split('_')
  587. arr.pop()
  588. path = arr.join('_')+'_cur-'+e
  589. }
  590. router.push({
  591. path:path
  592. });
  593. //getInitData(params);
  594. };
  595. const filterSort = (index) => {
  596. if (indexNum.value == index) {
  597. return;
  598. }
  599. indexNum.value = index;
  600. params.current = 1;
  601. scrollTop.value = document.body.scrollTop || document.documentElement.scrollTop;
  602. let query = {};
  603. if (route.query.categoryId) {
  604. query.categoryId = route.query.categoryId;
  605. } else if (route.query.keyword) {
  606. query.keyword = route.query.keyword;
  607. } else if (route.query.storeId) {
  608. query.storeId = route.query.storeId;
  609. }
  610. if (route.query.goodsIds) {
  611. query.goodsIds = route.query.goodsIds;
  612. }
  613. if (route.query.brandId) {
  614. query.brandId = route.query.brandId;
  615. }
  616. router.push({
  617. path: "list",
  618. query: {
  619. ...query,
  620. sort: indexNum.value,
  621. },
  622. });
  623. };
  624. //页数改变的方法-end
  625. //商品是否自营-start
  626. const isOwnShop = ref(false);
  627. const filterStoreSelf = (e) => {
  628. isOwnShop.value = !e;
  629. params.isSelf = isOwnShop.value ? 1 : 0;
  630. getInitData(params);
  631. };
  632. //商品是否自营-end
  633. //收藏及取消收藏商品
  634. const collectGoods = (defaultProductId, isFollowGoods) => {
  635. if (filtersStore.getLoginFlag) {
  636. //已登录
  637. let params = {
  638. productIds: defaultProductId,
  639. isCollect: !isFollowGoods,
  640. };
  641. post("v3/member/front/followProduct/edit", params).then((res) => {
  642. if (res.state == 200) {
  643. ElMessage.success(res.msg);
  644. goodsData.data.map((goodsItem) => {
  645. if (goodsItem.defaultProductId == defaultProductId) {
  646. goodsItem.isFollowGoods = !isFollowGoods;
  647. }
  648. });
  649. } else {
  650. ElMessage.error(res.msg);
  651. }
  652. });
  653. } else {
  654. //未登录提示登录
  655. return openLoginDialog({
  656. onRegister: () => {
  657. router.push({
  658. path: "/register",
  659. });
  660. },
  661. onForgot: () => {
  662. router.push({
  663. path: "/member/login/forget",
  664. });
  665. },
  666. });
  667. }
  668. };
  669. //属性选择--start
  670. const attriOption = (attributeName, attributeValue, attributeId, attributeValueId) => {
  671. attriList.value.push(attributeValueId)
  672. attriListTemp.value.push({
  673. name: attributeName,
  674. value: attributeValue,
  675. type: 'attr',
  676. id: attributeId,
  677. valueId: attributeValueId
  678. })
  679. params.attributeInfo = attriList.value.join(',')
  680. get('v3/goods/front/goods/goodsList', params).then(res => {
  681. if (res.state == 200) {
  682. goodsData.data = res.data.list
  683. goodsData.page = res.data.pagination
  684. }
  685. })
  686. };
  687. const goodsCate3 = ref(null); //获取dom的ref,名字同名
  688. const attriKick = (index, item) => {
  689. attriListTemp.value.splice(index, 1)
  690. if (item.type == "attr") {
  691. attriList.value = attriList.value.filter(subitem => subitem != item.valueId)
  692. proxy.refs.goodsCate3.attrSorH(item.id);
  693. if (attriListTemp.value.length) {
  694. params.attributeInfo = attriList.value.join(',')
  695. get('v3/goods/front/goods/goodsList', params).then(res => {
  696. if (res.state == 200) {
  697. goodsData.data = res.data.list
  698. goodsData.page = res.data.pagination
  699. }
  700. })
  701. } else {
  702. delete params.attributeInfo
  703. get('v3/goods/front/goods/goodsList', params).then(res => {
  704. if (res.state == 200) {
  705. goodsData.data = res.data.list
  706. goodsData.page = res.data.pagination
  707. }
  708. })
  709. }
  710. } else if (item.type == "brand") {
  711. delete params.brandIds
  712. proxy.refs.goodsCate3.brandSorH()
  713. get('v3/goods/front/goods/goodsList', params).then(res => {
  714. if (res.state == 200) {
  715. goodsData.data = res.data.list
  716. goodsData.page = res.data.pagination
  717. }
  718. })
  719. }
  720. };
  721. const brandOption = (brandId, brandName) => {
  722. attriListTemp.value.push({
  723. name: '品牌',
  724. value: brandName,
  725. type: 'brand',
  726. })
  727. params.brandIds = brandId
  728. get('v3/goods/front/goods/goodsList', params).then(res => {
  729. goodsData.data = res.data.list
  730. goodsData.page = res.data.pagination
  731. })
  732. };
  733. //属性选择--end
  734. //监听事件--start
  735. watchEffect(() => {
  736. if (routeParams.data.keyword != undefined) {
  737. // keyword.value = routeParams.data.keyword;
  738. // categoryId3.value = "";
  739. // showIndex.value = -1;
  740. // catePathName.path = [];
  741. // params.keyword = keyword.value;
  742. // delete params.categoryIds;
  743. // getInitData(params);
  744. // useHead({
  745. // title: keyword.value,
  746. // });
  747. } else if (categoryIds) {
  748. categoryId3.value = categoryIds.value;
  749. // keyword.value = "";
  750. // params.categoryIds = categoryIds;
  751. // delete params.keyword;
  752. // getInitData(params);
  753. }
  754. });
  755. watch(
  756. () => params.current,
  757. (nv, ov) => {
  758. if (nv != ov) {
  759. pagitionCurrent.value = Number(nv)
  760. }
  761. }
  762. );
  763. watch(
  764. () => categoryIds.value,
  765. (nv, ov) => {
  766. if (nv != ov) {
  767. categoryId3.value = nv;
  768. attriList.value = [];
  769. attriListTemp.value = [];
  770. isOwnShop.value = false;
  771. }
  772. }
  773. );
  774. watch(
  775. () => keyword.value,
  776. (nv, ov) => {
  777. if (nv != ov) {
  778. lowprice.value = highprice.value = null;
  779. isOwnShop.value = false;
  780. }
  781. }
  782. );
  783. //监听事件--end
  784. router.beforeEach((to, from) => {
  785. if (to.path == from.path) {
  786. document.body.scrollTop = scrollTop.value;
  787. }
  788. });
  789. onMounted(() => {
  790. setTimeout(() => {
  791. sldStatEvent({ behaviorType: 'pv',pageUrl: defaultUrl + router.currentRoute.value.path, referrerPageUrl: apiUrl });
  792. }, 3000)
  793. nextTick(() => {
  794. clacRouteParams()
  795. });
  796. });
  797. //返回值
  798. </script>
  799. <style lang="scss" scoped>
  800. @import "@/assets/style/goodsList.scss";
  801. @import "@/assets/style/base.scss";
  802. input[type="checkbox"] {
  803. display: none;
  804. vertical-align: middle;
  805. margin-bottom: 3px;
  806. margin-right: 3px;
  807. }
  808. input[type="checkbox"] + label {
  809. background: url("/goods/unsel.png") left center no-repeat;
  810. padding-left: 20px;
  811. background-size: 12px 12px;
  812. }
  813. input[type="checkbox"]:checked + label {
  814. background-image: url("/goods/select.png");
  815. }
  816. .empty_page {
  817. flex-direction: column;
  818. padding: 100px;
  819. }
  820. .sld_pagination {
  821. padding: 30px 0;
  822. }
  823. /*添加css样式*/
  824. input::-webkit-outer-spin-button,
  825. input::-webkit-inner-spin-button {
  826. -webkit-appearance: none;
  827. }
  828. input[type="number"] {
  829. -moz-appearance: textfield;
  830. }
  831. </style>